package br.affero.web.controller;

import java.util.Date;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.jboss.solder.logging.Logger;

import br.affero.core.person.dao.PersonDao;
import br.affero.core.person.model.Person;
import br.affero.util.JsfUtil;

@Named
public class TutorialController {
	private static Logger logger = Logger.getLogger(TutorialController.class);
	private static final String GENERIC_ERROR = "Ocorreu um erro genérico!";
	
	@Inject
	PersonDao personDao;
	
	private List<Person> personList = null;
	
	public Date systemDate() {
		return new Date();
	}

	
	/*private List<Person> mockPersons() {
		List<Person> result = new ArrayList<Person>();
		
		personDao.findAll();
		
		Person person1 = new Person();
		person1.setActive(true);
		person1.setName("Paulo Neves");
		person1.setBirthDate(new Date(76,1,20));
		person1.setPersonExperiences(new ArrayList<Experience>());
		person1.setPersonId(1);
		
		result.add(person1);
		
		person1 = new Person();
		person1.setActive(true);
		person1.setName("Pessoa 2");
		person1.setBirthDate(new Date());
		person1.setPersonExperiences(new ArrayList<Experience>());
		person1.setPersonId(2);
		
		result.add(person1);
		
		person1 = new Person();
		person1.setActive(true);
		person1.setName("Pessoa 3");
		person1.setBirthDate(new Date());
		person1.setPersonExperiences(new ArrayList<Experience>());
		person1.setPersonId(3);
		
		result.add(person1);
		
		return result;
	}*/
	
	 /**
     * Obter lista de pessoa
     * 
     * @return
     */
    public List<Person> getPersonList() {
            if (personList == null) {
                    try {
                            personList = personDao.findAll();
                    } catch (Exception e) {                         
                            JsfUtil.addErrorMessage(GENERIC_ERROR);
                            logger.error(GENERIC_ERROR,e);
                    }
            }
            return personList;
    }
}
